package com.pig4cloud.pig.village.file.controller;

import com.pig4cloud.pig.village.api.entity.VillageImage;
import com.pig4cloud.pig.village.file.service.IFileService;
import com.pig4cloud.pig.village.file.service.IImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @author limbray.li
 * @date 2021/7/13
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/file")
@Api(value = "file", tags = "文件")
public class FileController {
	@Resource
	private IFileService fileService;
	@Resource
	private IImageService imageService;

	@ApiOperation(value = "获取文件")
	@GetMapping("/getfile")
	public void getFile(@ApiParam("文件名") String name, HttpServletResponse response) {
		VillageImage image = imageService.getImageByObjectName(name);
		fileService.getFile(image.getUrl(),image.getFileName(),response);
	}
}
